//frame管理
var view = new Object;
view.set = new Object;//层集合初始化
view.stack = new Object;//层stack
view.stack.length=0;
view.set = $('.frame');//层集合初始化
view.set.css({//为层设置基本样式
  'position':'absolute',
  'width':'100%',
  'height':'100%',
  'top':'0',
  'left':'0',
  'background':'#eee',
  'z-index':'0',
  'opacity':'0',
  'visibility':'hidden',
  'display':'none'
});
var close =$('<div class="close">&lt;return</div>');//为层添加关闭层的按钮
close.css({'height':'100px','color':'#2196f3','font-size':'30px','display':'inline'});
view.set.prepend(close);
$('.close').click(function(){
  view.unload($(this).parent());
});
view.set.scrollTopValue=0;
view.load = function(farmeSelector){//根据一个jQuerselector来加载层
  var nowView=view.set.filter(farmeSelector);
  view.stack[++view.stack.length]=nowView;//入stack
  //设置样式
  nowView.css({'display':'block'});
  //保存载入之前的滚动条高度
  nowView.scrollTopValue=$('body').scrollTop();
  //根据元素调整高度
  nowView.css({'height':$(document).height()+'px'})
  //滚动到顶部
  $('body').animate( {scrollTop: 0}, 200);
  nowView.css({'opacity':'100','visibility':'visible','z-index':view.stack.length+1});
}
view.unload = function(farmeSelector){
  var nowView=view.set.filter(farmeSelector);
  //动画渲染延迟bug
  try{
    //恢复原滚动条高度
    var height = view.stack[view.stack.length].scrollTopValue;
  }
  catch(err){
    var height = view.stack[++view.stack.length].scrollTopValue;
  }
  //出stack
  view.stack.length--;
  
  nowView.css({'opacity':'0','visibility':'hidden'});
  // 延时从dom中移除标记

  $('body').animate( {scrollTop: height}, 200);
  setTimeout(function(){nowView.css({'display':'none'});},305);
}
console.log(view)